package idea.think.adapter;

import idea.think.IdeaAll;
import idea.think.R;
import idea.think.vo.IdeaData;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

public class CustomIdeaAdapter extends ArrayAdapter<IdeaData> {
	public ArrayList<Integer> alist2 = new ArrayList<Integer>(); //Checkbox 담는 리스트 2
	IdeaAll iAll;
	
	public CustomIdeaAdapter(Context context, List<IdeaData> objects) {
		super(context, 0, objects);
		iAll = (IdeaAll)context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v;
		final ViewHolder holder;		
		LayoutInflater inflater = iAll.getLayoutInflater();
		
		if(convertView == null){
			v = inflater.inflate(R.layout.idea_dialog, null);
			holder = new ViewHolder();
			holder.cateText = (TextView) v.findViewById(R.id.ideaText01);
			holder.cateCheck = (CheckBox) v.findViewById(R.id.ideaCheck);
			v.setTag(holder);				
		}else{
			v = convertView;
			holder = (ViewHolder)v.getTag();
		}
		
		final IdeaData data = getItem(position);
		holder.cateText.setText(data.getIdea1() + ", " + data.getIdea2() + ", " + data.getIdea3());
		Cursor c = iAll.selectAllItem();
		c.moveToNext();			
				
		holder.cateCheck.setTag(String.valueOf(c.getInt(c.getColumnIndex("_id"))));
		holder.cateCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {			        
		        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {			      
		           if(holder.cateCheck.isChecked() == true){
		        	   Log.e("TA", "id = " + data.getIdeaCheck());
		        	   alist2.add(data.getIdeaCheck());
		           }
		        }
		});
		
		return v;
	}	
}
